<?php

namespace App\Models\ModelManage;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class JsonField
 * @package App\Models\ModelManage
 * @version August 7, 2018, 5:45 pm CST
 *
 * @property \App\Models\ModelManage\Table table
 * @property \App\Models\ModelManage\TableField tableField
 * @property integer table_id
 * @property integer table_field_id
 * @property string schema
 * @property string data
 */
class JsonField extends Model
{
    use SoftDeletes;

    public $table = 'json_fields';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'table_id',
        'table_field_id',
        'schema',
        'data',
        'type',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'table_id'       => 'integer',
        'table_field_id' => 'integer',
        'schema'         => 'string',
        'data'           => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [

    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function table()
    {
        return $this->hasOne(\App\Models\ModelManage\Table::class, 'id', 'table_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function tableField()
    {
        return $this->hasOne(\App\Models\ModelManage\TableField::class, 'id', 'table_field_id');
    }
}
